package com.spdzen.support;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class SpringContextUtils {	
	public static WebApplicationContext getWebApplicationContext() {
		return WebApplicationContextUtils.getRequiredWebApplicationContext(WebContextUtils.getRequest().getServletContext());
	}
	
	public static ApplicationContext getApplicationContext() {
		return WebApplicationContextUtils.getRequiredWebApplicationContext(WebContextUtils.getRequest().getServletContext());
	}
	
	public static <T> T getBean(String name, Class<T> requiredType) throws BeansException {
		WebApplicationContext context = getWebApplicationContext();
		return context.getBean(name, requiredType);
	}
}
